Skip to content

Type HTMLImageElement.crossOrigin as a literal union of known CORS values - #64179

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/htmlimageelement-crossorigin-fix
Draft

Type HTMLImageElement.crossOrigin as a literal union of known CORS values#64179
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/htmlimageelement-crossorigin-fix

Conversation

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

HTMLImageElement.crossOrigin was declared as string | null, so invalid values type-checked:

new Image().crossOrigin = "abc"; // no error

The HTML spec defines it as reflecting crossorigin limited to only known valuesanonymous and use-credentials, with the empty string mapping to anonymous.

Changes

  • lib.dom.d.ts: crossOrigin: string | nullcrossOrigin: "anonymous" | "use-credentials" | "" | null on HTMLImageElement. null is retained (assigning it removes the attribute; the getter returns null when absent); "" is retained as a valid author value (<img crossorigin>). This matches the existing decoding: "async" | "sync" | "auto" pattern in the same interface.
  • htmlImageElementCrossOrigin.ts: new compiler test covering each valid assignment, the invalid one, and reading the property into the literal union. Committed in its failing state first, so the baseline diff shows the behavior change.
htmlImageElementCrossOrigin.ts(7,1): error TS2322: Type '"abc"' is not assignable to
  type '"" | "anonymous" | "use-credentials" | null'.

Notes for reviewers

Two open questions:

  • This file is generated. tsc/internal/bundled/README.md states the DOM libs aren't meant to be hand-edited and that changes belong in TypeScript-DOM-lib-generator. This edit will be lost on regeneration unless mirrored upstream — treat it as the desired outcome rather than the durable fix.
  • Scope and compatibility. Limited to HTMLImageElement to match the issue, leaving HTMLScriptElement, HTMLLinkElement, HTMLMediaElement, and SVGImageElement as string | null. It's also breaking for code assigning a plain string (e.g. from getAttribute), which now needs narrowing or a cast. Since the setter accepts arbitrary strings at runtime, this is an authoring-surface improvement rather than a reflection of runtime behavior.

No compiler code changed; the full suite showed no baseline fallout beyond the new test.

@typescript-automation typescript-automation Bot added For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 5, 2026
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 5, 2026
Copilot AI and others added 2 commits September 5, 2026 07:25
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crossOrigin type to use literal union Type HTMLImageElement.crossOrigin as a literal union of known CORS values Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTMLImageElement#crossOrigin should use literal union type from allowable values

2 participants